package com.sqoq.downloader3.ui

import android.view.WindowManager
import androidx.core.view.children
import com.sqoq.downloader3.App
import com.sqoq.downloader3.R
import com.sqoq.downloader3.base_ddg.BaseDialogFragment_ddg
import com.sqoq.downloader3.base_ddg.DialogFragmentHelper_ddg
import com.sqoq.downloader3.databinding.DialogStepDdgBinding
import com.sqoq.downloader3.getLanguageString_ddg
import com.sqoq.downloader3.lanuage_ddg.StringId_ddg


class StepDialogFragment_ddg(override val layout: Int = R.layout.dialog_step_ddg) :
    BaseDialogFragment_ddg<DialogStepDdgBinding>() {
    override fun initDialogFragmentProperty(dialogFragmentHelper_ddg: DialogFragmentHelper_ddg?) {
        dialogFragmentHelper_ddg?.width = WindowManager.LayoutParams.MATCH_PARENT
        dialogFragmentHelper_ddg?.height = WindowManager.LayoutParams.MATCH_PARENT
//        dialogFragmentHelper_ddg?.setMaskLayerTransparent()

    }

    var step = 0
    override fun init() {
        binding.NEXTDdg.setOnClickListener {
            step += 1
            if (step > 3) {
                step = 3
                dismiss()
            }
            setSep()

        }
        binding.SKIPDdg.setOnClickListener {
            step -= 1
            if (step < 0) {
                step = 0
            }
            setSep()
        }

        setSep()
    }

    fun setSep() {
        binding.magicIndicator.children.forEachIndexed { index2, view ->
            kotlin.runCatching {
                if (step == index2) {
                    view.setBackgroundResource(R.drawable.bb2_ddg)
                } else {
                    view.setBackgroundResource(R.drawable.bb_ddg)
                }
            }
        }
        binding.numDdg.text = (step + 1).toString()
        when (step) {

            0 -> {
                binding.imgDdg.setImageResource(R.mipmap.step1_ddg)
                binding.textDdg.text = App.app.getLanguageString_ddg(StringId_ddg.step1_ddg)
            }

            1 -> {

                binding.imgDdg.setImageResource(R.mipmap.step2_ddg)
                binding.textDdg.text = App.app.getLanguageString_ddg(StringId_ddg.step2_ddg)
            }

            2 -> {

                binding.imgDdg.setImageResource(R.mipmap.step3_ddg)
                binding.textDdg.text = App.app.getLanguageString_ddg(StringId_ddg.step3_ddg)
            }

            3 -> {

                binding.imgDdg.setImageResource(R.mipmap.step4_ddg)
                binding.textDdg.text = App.app.getLanguageString_ddg(StringId_ddg.step4_ddg)
            }

            else -> {

            }

        }
    }

    override fun initData() {
    }
}